<template>  
<view>
	<uni-card :title="title" :sub-title="username"  :thumbnail="avatar" @click="onClick">
	</uni-card>
  <el-table  
    :data="tableData"  
    stripe  
    style="width: 100%">  
    <el-table-column  
      v-for="(column, index) in columns"  
      :key="index"  
      :prop="column.prop"  
      :width="column.width">
    </el-table-column>
  </el-table>
  <view>
	  <view class="" style="background-color: white;padding-bottom: 15px;" v-if="list">
	  	<uni-forms-item style="margin-bottom: unset;margin-left: 10px;">附件:</uni-forms-item>
	  	<cl-upload v-model="list" :add="false" :remove="false" style="margin-left: 15px;"></cl-upload>
	  </view>
	  
  <!-- 循环拿值 -->
  <div class="radio">
      审批流程
    </div>
	
    <view class="" v-for="(item, index) in items" :key="index">
    	<view class="cu-timeline">
    	    <view class="cu-time">审批人</view>
    	    <view class="cu-item text-blue">  
    	    <view class="flex">
    	    	<view class="flex margin-right-sm padding-sm bg-gray radius" v-for="(itemData,indexData) in item.approverUserDtos" style="align-items: center;">
    	    			<view class="cu-avatar lg" :style="{ backgroundImage: `url(${itemData.assPortrait})` }"></view>  
    	    			<view class="text-grey margin-left-sm">{{ itemData.assessorName }}  </view>
						<view class="cu-tag round light" style="color: limegreen;" v-if="itemData.assStatus!=0">已审批</view>
						<view class="cu-tag round light" style="color: coral;" v-if="itemData.assStatus==0">未审批</view> 
    	    	</view>
    	    </view>
    	    </view>  
    	</view>
    </view>  
	
	<view class="" v-for="(item, index) in copys" :key="index">
		<view class="cu-timeline">
		    <view class="cu-time">抄送人</view>
		    <view class="cu-item text-blue">  
		    <view class="flex">
		    	<view class="flex margin-right-sm padding-sm bg-gray radius" style="align-items: center;">
		    			<view class="cu-avatar lg" :style="{ backgroundImage: `url(${item.copyPortrait})` }"></view>  
		    			<view class="text-grey margin-left-sm">{{ item.username }}  </view>
		    	</view>
		    </view>
		    </view>  
		</view>
	</view>  	
	<view>
    </view>
    <view class="flex justify-around ">
   	    <button class="xl" type="primary" @click="submit()" style="width: 45%;" v-if="!status">通过</button>
    	<button  class="xl"  type="warn" @click="reject()" style="width: 45%;" v-if="!status">驳回</button>
    </view>
  </view>
	</view>
</template>  
  
<script>  
	import request from '../../common/request';
	import common from 'common/common.js';
  export default {  
    data() {  
      return {  
		  // 图片显示
		 list: undefined,  
		 items: [],  
		 copys:[],
		  						
		avatar: '',
		title:'',
		username:'',
		fromId:'',
		staff:{},
		userId:'',
		  				extraIcon:{
		  					color: '#4cd964',
		  					size: '22',
		  					type: 'gear-filled'
		  				},
		  
        tableData: [],  
        columns: [ 
          { prop: 'dataAttribution',  width: 180 },  
          { prop: 'dataContent',  width: 180 }  
        ]
      }  
    },  
	onLoad(e) {
		this.staff = uni.getStorageSync("staff");
		this.fromId= e.fromId;
		this.status = e.status;
		console.log(this.status)
		//this.fromId= "10";
		console.log("跳转数据:"+this.fromId)
		this.selectFrom()
	},
	methods : {
		
		/* 通过审核 */
		submit(){
			request({
				url: common.base_url+"/system/form/approveApproval",
				data:{
					"FromId":this.fromId,
				},
				header:{
				},
				method: 'POST',
				success: res => {
					var code = res.data.code;
					var msg = res.data.msg;
					if(code==200){
						uni.showToast({
							title:"处理成功!",
							Icon:"success"
						})
						uni.navigateBack({
						    delta: 1,
						});
					}else{
						uni.showToast({
							title:msg,
							icon:"error"
						})
					}
				},
				fail: function(e) {
					uni.showToast({
						title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
						icon:"loading"
					})
				},
			})
			
		},
		reject(){
			request({
				url: common.base_url+"/system/form/rejectApproval",
				data:{
					"FromId":this.fromId,
					"rejectRemark":this.rejectRemark
				},
				header:{
				},
				method: 'POST',
				success: res => {
					var code = res.data.code;
					var msg = res.data.msg;
					if(code==200){
						uni.showToast({
							title:"处理成功!",
							Icon:"success"
						})
						uni.navigateBack({
						    delta: 1,
						});
					}else{
						uni.showToast({
							title:msg,
							icon:"error"
						})
					}
				},
				fail: function(e) {
					uni.showToast({
						title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
						icon:"loading"
					})
				},
			})
			
			
		},
		onClick(e){
						console.log(e)
					},
					actionsClick(text){
						uni.showToast({
							title:text,
							icon:'none'
						})
					},
					
		selectFrom(){
			uni.showLoading({ title: '加载中', mask: true });
			request({
				url: common.base_url+"/system/form/queryApproval/"+this.fromId,
				data:{
					
				},
				header:{
				},
				method: 'GET',
				success: res => {
					console.log(res.data.data)
					var code = res.data.code;
					var msg = res.data.msg;
					if(code==200){
						// uni.showToast({
						// 	title:"加载完成!",
						// 	Icon:"success"
						// })
						this.avatar = res.data.data.imageUsername;
						this.title = res.data.data.fromName;
						this.username = res.data.data.username;
						this.tableData =  res.data.data.tdataInfos;
						this.items=res.data.data.pathApprovers;
						this.copys = res.data.data.copyUsers;
						var tableItem= this.tableData.find(i => i.identification === 'image');
						if(tableItem){
							var idsArray = tableItem.dataContent.split(",");
							this.list = idsArray.map(e => ({ "path": e})); 
							this.tableData.pop();
						}
						/* uni.navigateBack({
						    delta: 1,
						}); */
					}else{
						uni.showToast({
							title:msg,
							icon:"error"
						})
					}
					uni.hideLoading();
				},
				fail: function(e) {
					uni.showToast({
						title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
						icon:"loading"
					})
					uni.hideLoading();
				},
					
			})
		}
	}
  }   
</script>